<template>
  <div>
   <h2>登录</h2>
   <hr>
   <table border="1">
    <tr>
      <td>账号:</td>
      <td>
        <input type="text" v-model="state.Name">
      </td>
    </tr>
    <tr>
      <td>密码:</td>
      <td>
        <input type="password" v-model="state.Pwd">
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="button" value="登录" @click="Login">
      </td>
      
    </tr>
   </table>
  </div>
</template>

<script setup lang="ts">
import{reactive,toRefs,onMounted} from 'vue';
import{useRouter,useRoute} from 'vue-router';
import axios from 'axios';

const router=useRouter();
const route=useRoute();

let data:any=reactive({
  state:{
    Name:'',
    Pwd:''
  }
})
let {state}=toRefs(data);

function Login(){
  let obj={
    Name:state.value.Name,
    Pwd:state.value.Pwd
  }
  if(obj.Name=="")
  {
    alert('账号不能为空');
    return 
  }
  if(obj.Pwd=="")
  {
    alert('密码不能为空');
    return 
  }
  axios({
    url:'https://localhost:7064/api/Admin/Login',
    method:'post',
    params:obj
  })
  .then(res=>{
    if(res.data.data==-1)
  {
    alert('账号不存在,请重新输入');
    return 
  }
  if(res.data.data==-2)
  {
    alert('密码错误');
    return 
  }
  if(res.data.data>0)
  {
    alert('登录成功');
    router.push('/MDAdd')
  }
  })
  .catch(err=>{
    console.log(err)
  })


}


</script>

<style scoped>

</style>